<?php

use Illuminate\Database\Seeder;
use App\Models\Permission;
use App\Models\Role;
use App\User;
use Carbon\Carbon;

/*

php artisan migrate:refresh --seed && php artisan passport:install --force

 */

class SetUpTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // DB::update('ALTER TABLE users AUTO_INCREMENT = 1');

        $admin = User::create([
          'phone'     => '15317876176',
          'password'  => '15317876176',
          'level'     => 0,
          'parent_id' => null,
        ]);
       

        $proot = Permission::create([
            'name'          =>  'super.admin',
            'display_name'  =>  '拥有所有权限',
            'guard_name'    =>  'api',
        ]);

        $houtai = $proot->children()->create([
            'name'          =>  'sys.backstage',
            'display_name'  =>  '系统后台',
            'guard_name'    =>  'api',
        ]);

        $qudao = $houtai->children()->create([
              'name'          =>  '_agent.about',
              'display_name'  =>  '渠道相关',
              'guard_name'    =>  'api',
              'description'   =>  '',
        ]);

        $qudao->children()->createMany([
          [
              'name'          =>  'agent.manage',
              'display_name'  =>  '渠道信息',
              'guard_name'    =>  'api',
              'description'   =>  '',
          ],[
              'name'          =>  'order.input',
              'display_name'  =>  '订单录入',
              'guard_name'    =>  'api',
              'description'   =>  '',
          ],[
              'name'          =>  'comm.track',
              'display_name'  =>  '业绩追踪',
              'guard_name'    =>  'api',
              'description'   =>  '',
          ]
        ]);


        $caiwu = $houtai->children()->create([
              'name'          =>  '_finance.center', //
              'display_name'  =>  '财务中心',
              'guard_name'    =>  'api',
              'description'   =>  '',
        ]);



        $caiwu->children()->createMany([
          [
              'name'          =>  'order.bill',
              'display_name'  =>  '账单结算',
              'guard_name'    =>  'api',
              'description'   =>  '',
          ],[
              'name'          =>  'pd.cash',
              'display_name'  =>  '提现管理',
              'guard_name'    =>  'api',
              'description'   =>  '',
          ],[
              'name'          =>  'pd.log',
              'display_name'  =>  '余额明细',
              'guard_name'    =>  'api',
              'description'   =>  '',
          ]
        ]);

        $quanxian = $houtai->children()->create([
              'name'          =>  '_role.other',
              'display_name'  =>  '权限&其他',
              'guard_name'    =>  'api',
              'description'   =>  '',
        ]);

        $quanxian->children()->createMany([
            [
              'name'          =>  'role.permission',
              'display_name'  =>  '角色权限',
              'guard_name'    =>  'api',
              'description'   =>  '',
            ],[
              'name'          =>  'op.log',
              'display_name'  =>  '操作日志',
              'guard_name'    =>  'api',
              'description'   =>  '',
            ],[
              'name'          =>  'sys.set',
              'display_name'  =>  '系统设置',
              'guard_name'    =>  'api',
              'description'   =>  '',
            ]
        ]);

        $role = Role::create([
            'name'          =>  'super-admin',
            'display_name'  =>  '超级管理员用户',
            'guard_name'    =>  'api' ,
            'description'   =>  '拥有所有权限'
        ]);

        $role->givePermissionTo('super.admin');

        

        $role = Role::create([
            'name'          =>  'agent',
            'display_name'  =>  '渠道代理',
            'guard_name'    =>  'api' ,
            'description'   =>  '渠道代理用户'
        ]);

        $role = Role::create([
            'name'          =>  'cfo',
            'display_name'  =>  '财务',
            'guard_name'    =>  'api' ,
            'description'   =>  '财务人员'
        ]);


        $role = Role::create([
            'name'          =>  'om',
            'display_name'  =>  '运营',
            'guard_name'    =>  'api' ,
            'description'   =>  '运营人员'
        ]);

        User::find(1)->assignRole("agent");
        User::find(1)->assignRole("super-admin");

/*        User::find(1)->assignRole("agent");
        User::find(1)->assignRole("super-admin");*/

/*        User::find(2)->assignRole("agent");


      Config::create([
        'name'          =>  'grade_comm_set',
        'display_name'  =>  '渠道等级设置',
        'value'         =>  "",
        'value2'        =>  "",
        'value3'        =>  "",
        'editor'        =>  '{"type":"datagrid","column":[{"title":"渠道头衔"},{"title":"渠道提点(%)","type":"number"},{"title":"推荐奖励(%)"}],"data_src":[["grade_title_1","grade_rate_1","grade_tj_rate_1"],["grade_title_2","grade_rate_2","grade_tj_rate_2"]]}',
        'group'         =>  '渠道相关',
        'description'   =>  ""
      ]);

      Config::create([
        'name'          =>  'grade_title_1',
        'display_name'  =>  '',
        'value'         =>  '业绩股东',
        'editor'        =>  'text',
        'group'         =>  "",
        'display'       =>  0,
        'description'   =>  ""
      ]);

      Config::create([
        'name'          =>  'grade_title_2',
        'display_name'  =>  '',
        'value'         =>  '店家',
        'editor'        =>  'text',
        'group'         =>  "",
        'display'       =>  0,
        'description'   =>  ""
      ]);

      Config::create([
        'name'          =>  'grade_rate_1',
        'display_name'  =>  '',
        'value'         =>  '55',
        'editor'        =>  'number',
        'group'         =>  "",
        'display'       =>  0,
        'description'   =>  ""
      ]);

      Config::create([
        'name'          =>  'grade_rate_2',
        'display_name'  =>  '',
        'value'         =>  '45',
        'editor'        =>  'number',
        'group'         =>  "",
        'display'       =>  0,
        'description'   =>  ""
      ]);

      Config::create([
        'name'          =>  'grade_tj_rate_1',
        'display_name'  =>  '',
        'value'         =>  '3',
        'editor'        =>  'number',
        'group'         =>  "",
        'display'       =>  0,
        'description'   =>  "推荐佣金"
      ]);

      Config::create([
        'name'          =>  'grade_tj_rate_2',
        'display_name'  =>  '',
        'value'         =>  '0',
        'editor'        =>  'number',
        'group'         =>  "",
        'display'       =>  0,
        'description'   =>  "推荐佣金"
      ]);

      Log::create([
        'user_id' => 1,
        'user_name' => "管理员",
        'method'  => 'POST',
        'input'   => "[]",
        'ip'      => request()->getClientIp(),
        'path'    => '/install'
      ]);*/

    }
}
